package com.example.controller;

import java.util.HashMap;
import java.util.List;
import java.util.Map;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;
import org.springframework.web.bind.annotation.RestController;

import com.example.entity.AskersEntity;
import com.example.entity.AskersVoEntity;
import com.example.service.AskersService;

@RequestMapping("/askers")
@RestController
public class AskersController {
	@Autowired
	private AskersService askersService;
	
	/**
	 * 多条件查询
	 * @param userVO
	 * @return
	 */
	@RequestMapping("/GetUsersLayUI")
	public Map<String, Object> GetUsersLayUI(AskersVoEntity askersVoEntity){
		Map<String, Object> reMap=new HashMap<String, Object>();
		askersVoEntity.setOffset((askersVoEntity.getPage()-1)*askersVoEntity.getLimit());
		List<AskersEntity> list=askersService.GetUsersLayUI(askersVoEntity);
		int count=askersService.getCount(askersVoEntity);
		reMap.put("code","0");
		reMap.put("msg", "success");
		reMap.put("count", count);
		reMap.put("data", list);
		return reMap;
	}
	
	/**
	 *  查询全部
	 * @param id
	 * @return
	 */
	@PostMapping(path = "/selectListAll")
	public Map<String, Object> selectListAll() { // 受影响的行数
		
		List<AskersEntity> list = askersService.selectListAll();
		Map<String, Object> rsMap =new HashMap<String, Object>();
		rsMap.put("code", "code");
		rsMap.put("msg","");
		rsMap.put("count", list.size());
		rsMap.put("data",list);
		return rsMap;

	}
	/**
	 * 修改权重
	 * @param weight
	 * @return
	 */
	@RequestMapping("/weight")
	@ResponseBody
	public Map<String, Object> upMoAskers(AskersEntity weight) { // 受影响的行数 
		int rows = askersService.upMoAskers(weight);
		Map<String, Object> rsMap =new HashMap<String, Object>();
		rsMap.put("code", rows > 0 ? "0" : "1");
		rsMap.put("msg", rows > 0 ? "修改成功" : "修改失败");
		return rsMap;

	}
	/**
	 * 获取咨询师
	 * @return
	 */
	@GetMapping("/getConsultant")
	@ResponseBody
	public List<AskersEntity> getConsultant(){
		return askersService.getTBConsultant();
	}
}
